﻿module TagLang

type public TagQueryTree = 
 Val of string
| AND of TagQueryTree * TagQueryTree
| OR of TagQueryTree * TagQueryTree
| NOT of TagQueryTree
|GET of TagQueryTree

//let q = GET(AND(Val("social"),Val("socail"));


//let rec compute = function
//  |Val(n)     -> n
//  |GET(e)     -> "select * from Urls inner join (select b.UrlId from Bookmarks as b  left join Urls as u on u.UrlId = b.UrlId left join Tags as t on t.TagId = b.TagId where t.Text in ('social', 'socail')  group by b.UrlId having count(*)= 2 ) as bkmrk on bkmrk.UrlId = Urls.UrlId"
//  |AND(e1,e2) -> (compute e1) + " и " + (compute e2)
//  |NOT(e)     -> " не содержат " + (compute e)
//  |OR(e1,e2)  -> (compute e1) + " или " + (compute e2)

  //select * from Urls inner join (select b.UrlId from Bookmarks as b  left join Urls as u on u.UrlId = b.UrlId left join Tags as t on t.TagId = b.TagId where t.Text in ('social', 'socail')  group by b.UrlId having count(*)= 2 ) as bkmrk on bkmrk.UrlId = Urls.UrlId 